<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发布新闻</title>
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <link type="text/css" rel="stylesheet" href="css/index.css">
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
    <div id="app">
        <el-form ref="form" :model="editForm" label-width="120px" class="demo-ruleForm">

            <div style="width: 345px">
                <el-form-item label="新闻标题">
                    <el-input v-model="editForm.title"></el-input>
                </el-form-item>
            </div>

            <el-form-item label="新闻类别" prop="kid">
                <el-select v-model="editForm.kid" placeholder="请选择">
                    <el-option
                            v-for="item in kinds"
                            :key="item.id"
                            :label="item.kind"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="设置上传时间" prop="time">
                <el-date-picker
                        v-model="editForm.time"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
                </el-date-picker>
            </el-form-item>

            <div style="width: 550px">
                <el-form-item label="新闻的详细内容">
                    <el-input type="textarea"  resize="none" :rows="5" v-model="editForm.content"></el-input>
                </el-form-item>
            </div>

            <el-form-item>
                <el-button type="primary" @click="onSubmit">立即创建</el-button>
            </el-form-item>

        </el-form>
    </div>

    <script>
        var app = new Vue({
            el:"#app",
            data:{
                kinds:[],
                editForm:{},
            },
            created(){
                this.kindInit();
            },
            methods: {
                kindInit(){
                    axios.post("/NewsSpecialController/kindAll").then(resp=>{
                        console.log(resp)
                        this.kinds=resp.data.data;
                    });
                },
                onSubmit(){
                    axios.post("/NewsSpecialController/addnews",this.editForm).then(resp=>{
                        this.$message.success("添加成功");
                    });
                },
            }
        });
    </script>
</body>
</html>